home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / sndplaydoublebuffer / _headers / doublebufferfromfile.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  13.2 KB  |  369 lines

  1. /*
  2.     File:        DoubleBufferFromFile.h
  3.  
  4.     Contains:    Headers for routines demonstrating how to play sound from disk using SndPlayDoubleBuffer.
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/31/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #ifndef __DOUBLEBUFFERFROMFILE__
  25. #define __DOUBLEBUFFERFROMFILE__
  26.  
  27. #include <AIFF.h>
  28. #include <Sound.h>
  29. #include <Files.h>
  30. #include <MixedMode.h>
  31. #include <StandardFile.h>
  32. #include <Fonts.h>
  33. #include <SegLoad.h>
  34. #include <Resources.h>
  35. #include <FixMath.h>
  36.  
  37. #if GENERATINGPOWERPC
  38. #include <fp.h>
  39. #endif
  40.  
  41. #ifndef __SOUNDSTRUCT__
  42. #include "SoundStruct.h"
  43. #endif
  44.  
  45. #ifndef __MYGESTALT__
  46. #include "MyGestalt.h"
  47. #endif
  48.  
  49. #ifndef __PRIVATE_DBFFFUNC__
  50. #include "Private_DBFFFunctions.h"
  51. #endif
  52.  
  53. #ifndef __INTERRUPT_ROUTINES__
  54. #include "Interrupt_Routines.h"
  55. #endif
  56.  
  57. #ifndef __DBFFERRORS__
  58. #include "DBFF_Errors.h"
  59. #endif
  60.  
  61. #ifndef __DEFINES__
  62. #include "Defines.h"
  63. #endif
  64.  
  65. /* Function definitions */
  66.  
  67. /*    Purpose:        This creates a new SoundInfo structure and initializes
  68.                     it by calling ASoundInit.
  69.     Side Effects:    None.
  70. */
  71. /*-----------------------------------------------------------------------*/
  72. SoundInfoPtr    ASoundNew                (OSErr *theErr);
  73. /*-----------------------------------------------------------------------*/
  74.  
  75. /*
  76.     Purpose:        Display a StandardFile dialog to select an AIFF file.
  77.                     Open the file selected by the user.
  78.     Side Effects:    None.
  79. */
  80. /*-----------------------------------------------------------------------*/
  81. OSErr            ASoundGetFileToPlay        (SoundInfoPtr theSoundInfo);
  82. /*-----------------------------------------------------------------------*/
  83.  
  84. /*
  85.     Purpose:        Checks a file to see if its header can be parsed
  86.                     and the file can be played.
  87.                     
  88.                     This will return an error if the sound will not play,
  89.                     returning noErr means that sound will play.
  90.     Side Effects:    None.
  91. */
  92. /*-----------------------------------------------------------------------*/
  93. OSErr            ASoundCanThisPlay        (CInfoPBPtr theFileInfo);
  94. /*-----------------------------------------------------------------------*/
  95.  
  96. /*
  97.     Purpose:        Wrapper function called to get ready to play a sound.
  98.                     Use this if you want to make sure that there is enough
  99.                     memory to play the sound.
  100.     Side Effects:    This will call routines that will allocate memory needed
  101.                     to all of the various structures needed by the Sound Manager
  102.                     and memory to be used as the sounds' buffers.
  103. */
  104. /*-----------------------------------------------------------------------*/
  105. OSErr            ASoundReadyForPlaying    (SoundInfoPtr theSoundInfo,
  106.                                         unsigned long bufferSize);
  107. /*-----------------------------------------------------------------------*/
  108.  
  109. /*
  110.     Purpose:        Call this after you have called ASoundReadyForPlaying to
  111.                     start playing the sound you prepaired.
  112.     Side Effects:    Starts the sound playing.
  113. */
  114. /*-----------------------------------------------------------------------*/
  115. OSErr            ASoundPlay                (SoundInfoPtr theSoundInfo);
  116. /*-----------------------------------------------------------------------*/
  117.  
  118. /*
  119.     Purpose:        Wrapper function called to start playing a sound.
  120.                     Use this if you are pretty sure the sound will play, or
  121.                     just don't care specifically what goes wrong.
  122.     Side Effects:    This will call routines that will allocate memory needed
  123.                     to all of the various structures needed by the Sound Manager
  124.                     and memory to be used as the sounds' buffers.
  125. */
  126. /*-----------------------------------------------------------------------*/
  127. OSErr            ASoundStartPlaying        (SoundInfoPtr theSoundInfo,
  128.                                         unsigned long bufferSize);
  129. /*-----------------------------------------------------------------------*/
  130.  
  131. /*
  132.     Purpose:        Stops the currently playing sound.
  133.     Side Effects:    Stopping the currently playing sound will cause the
  134.                     sound completion routine to run.
  135. */
  136. /*-----------------------------------------------------------------------*/
  137. OSErr            ASoundStop                (SoundInfoPtr theSoundInfo);
  138. /*-----------------------------------------------------------------------*/
  139.  
  140. /*
  141.     Purpose:        Wrapper so the user doesn't have to keep track of if
  142.                     the sound is playing or not.
  143.     Side Effects:    If resuming a sound and the user had also called
  144.                     ASoundPauseForAdjust this will reinstall the sound
  145.                     completion callback.
  146. */
  147. /*-----------------------------------------------------------------------*/
  148. OSErr            ASoundPause                (SoundInfoPtr theSoundInfo);
  149. /*-----------------------------------------------------------------------*/
  150.  
  151. /*
  152.     Purpose:        If the sound is paused, resume playing.  If the sound is
  153.                     playing, pause playing.
  154.                     This differs from ASoundPause because it actually stops
  155.                     the sound instead of pausing it.  When the sound is
  156.                     paused for adjusting you can reset where the sound will
  157.                     next start playing from without having to play the
  158.                     remainder of the current buffer.  This routine is used
  159.                     for the QuickTime style playing.
  160.     Side Effects:    Removes the callback from the sound channel because
  161.                     otherwise while adjusting the sound the Sound Manager
  162.                     would call our clean up routine.
  163.                     When resuming a sound ASoundStartPlaying will install
  164.                     our callback routine if necessary (if the sound wasn't
  165.                     already paused).
  166. */
  167. /*-----------------------------------------------------------------------*/
  168. OSErr            ASoundPauseForAdjust    (SoundInfoPtr theSoundInfo);
  169. /*-----------------------------------------------------------------------*/
  170.  
  171. /*
  172.     Purpose:        Sound is done playing, dispose of the memory we no
  173.                     longer need.
  174.     Side Effects:    None.
  175. */
  176. /*-----------------------------------------------------------------------*/
  177. OSErr            ASoundDonePlaying        (SoundInfoPtr theSoundInfo,
  178.                                         unsigned long options);
  179. /*-----------------------------------------------------------------------*/
  180.  
  181. /*
  182.     Purpose:        Returns the channel for the sound in case you want to
  183.                     send it specific commands.
  184.     Side Effects:    None.
  185. */
  186. /*-----------------------------------------------------------------------*/
  187. SndChannelPtr    ASoundGetChan            (SoundInfoPtr theSoundInfo);
  188. /*-----------------------------------------------------------------------*/
  189.  
  190. /*
  191.     Purpose:        Returns the name of the file containing the currently
  192.                     playing sound.
  193.     Side Effects:    None.
  194. */
  195. /*-----------------------------------------------------------------------*/
  196. OSErr            ASoundGetSoundName        (SoundInfoPtr theSoundInfo,
  197.                                         Str255 theName);
  198. /*-----------------------------------------------------------------------*/
  199.  
  200. /*
  201.     Purpose:        Gets the number of the current buffer
  202.                     (in the range 1 to ASoundGetNumBuffers()) of the
  203.                     currently playing sound.
  204.     Side Effects:    None.
  205. */
  206. /*-----------------------------------------------------------------------*/
  207. long            ASoundGetCurBuffer        (SoundInfoPtr theSoundInfo);
  208. /*-----------------------------------------------------------------------*/
  209.  
  210. /*
  211.     Purpose:        Sets which buffer should be the next buffer to play
  212.                     from (in the range 1 to ASoundGetNumBuffers())
  213.                     for the currently playing sound.
  214.     Side Effects:    None.
  215. */
  216. /*-----------------------------------------------------------------------*/
  217. OSErr            ASoundSetCurBuffer        (SoundInfoPtr theSoundInfo,
  218.                                         long newValue);
  219. /*-----------------------------------------------------------------------*/
  220.  
  221. /*
  222.     Purpose:        Gets the number of buffers that the currently playing
  223.                     sound will need to play in its entirety.
  224.     Side Effects:    None.
  225. */
  226. /*-----------------------------------------------------------------------*/
  227. long            ASoundGetNumBuffers        (SoundInfoPtr theSoundInfo);
  228. /*-----------------------------------------------------------------------*/
  229.  
  230. /*
  231.     Purpose:        Gets the length (in bytes) of the currently playing
  232.                     sound.  This number does not include any header bytes.
  233.     Side Effects:    None.
  234. */
  235. /*-----------------------------------------------------------------------*/
  236. long            ASoundGetNumTotalBytes    (SoundInfoPtr theSoundInfo);
  237. /*-----------------------------------------------------------------------*/
  238.  
  239. /*
  240.     Purpose:        Gets the number of bytes that will be played by the end
  241.                     of the current buffer of the currently playing sound.
  242.     Side Effects:    None.
  243. */
  244. /*-----------------------------------------------------------------------*/
  245. long            ASoundGetBytesCopied    (SoundInfoPtr theSoundInfo);
  246.  
  247. /*
  248.     Purpose:        Sets the location in the file where the next buffer
  249.                     should be filled from for the currently playing sound.
  250.     Side Effects:    None.
  251. */
  252. /*-----------------------------------------------------------------------*/
  253. OSErr            ASoundSetBytesCopied    (SoundInfoPtr theSoundInfo,
  254.                                         long newValue);
  255. /*-----------------------------------------------------------------------*/
  256.  
  257. /*
  258.     Purpose:        Gets the size of a buffer of the currently playing
  259.                     sound.  Multiply by two to know how much memory is
  260.                     reserved for buffering the currently playing sound.
  261.     Side Effects:    None.
  262. */
  263. /*-----------------------------------------------------------------------*/
  264. long            ASoundGetBufferSize        (SoundInfoPtr theSoundInfo);
  265. /*-----------------------------------------------------------------------*/
  266.  
  267. /*
  268.     Purpose:        Gets the UPP for the function that should be called when
  269.                     the currently playing sound finishes.
  270.     Side Effects:    None.
  271. */
  272. /*-----------------------------------------------------------------------*/
  273. SndCallBackUPP    ASoundGetSoundCallBack    (SoundInfoPtr theSoundInfo);
  274. /*-----------------------------------------------------------------------*/
  275.  
  276. /*
  277.     Purpose:        Sets the function that should be called when the the
  278.                     currently playing sound finishes.
  279.     Side Effects:    None.
  280. */
  281. /*-----------------------------------------------------------------------*/
  282. OSErr            ASoundSetSoundCallBack    (SoundInfoPtr theSoundInfo,
  283.                                         void* newValue);
  284. /*-----------------------------------------------------------------------*/
  285.  
  286. OSErr            ASoundMute                (SoundInfoPtr theSoundInfo,
  287.                                         Boolean newValue);
  288.  
  289. Boolean            ASoundIsMute            (SoundInfoPtr theSoundInfo);
  290.  
  291. /*
  292.     Purpose:        Says to play the currently playing sound backwards
  293.                     (reverses the sound in the buffer).
  294.     Side Effects:    Takes effect when the next sound buffer gets filled.
  295. */
  296. /*-----------------------------------------------------------------------*/
  297. OSErr            ASoundPlayBackwards        (SoundInfoPtr theSoundInfo,
  298.                                         Boolean newValue);
  299. /*-----------------------------------------------------------------------*/
  300.  
  301. /*
  302.     Purpose:        Returns true if the currently playing sound's buffer
  303.                     is set to be reversed.
  304.     Side Effects:    None.
  305. */
  306. /*-----------------------------------------------------------------------*/
  307. Boolean            ASoundIsBackwards        (SoundInfoPtr theSoundInfo);
  308. /*-----------------------------------------------------------------------*/
  309.  
  310. /*
  311.     Purpose:        Returns true if the sound has finished playing.
  312.     Side Effects:    None.
  313. */
  314. /*-----------------------------------------------------------------------*/
  315. Boolean            ASoundIsDone            (SoundInfoPtr theSoundInfo);
  316. /*-----------------------------------------------------------------------*/
  317.  
  318. /*
  319.     Purpose:        Changes the volume of the currently playing sound.
  320.                     The values you pass in are added to the current values.
  321.                     Negitive values will decrease the volume, positive values
  322.                     will increase the volume.
  323.     Side Effects:    None.
  324. */
  325. /*-----------------------------------------------------------------------*/
  326. OSErr            ASoundChangeVolume        (SoundInfoPtr theSoundInfo,
  327.                                         unsigned short leftVol,
  328.                                         unsigned short rightVol);
  329. /*-----------------------------------------------------------------------*/
  330.  
  331. /*
  332.     Purpose:        Gets the volume of the currently playing sound.
  333.     Side Effects:    None.
  334. */
  335. /*-----------------------------------------------------------------------*/
  336. OSErr            ASoundGetVolume            (SoundInfoPtr theSoundInfo,
  337.                                         unsigned short *leftVol,
  338.                                         unsigned short *rightVol);
  339. /*-----------------------------------------------------------------------*/
  340.  
  341. /*
  342.     Purpose:        Sets the volume of the currently playing sound.
  343.     Side Effects:    None.
  344. */
  345. /*-----------------------------------------------------------------------*/
  346. OSErr            ASoundSetVolume            (SoundInfoPtr theSoundInfo,
  347.                                         unsigned short leftVol,
  348.                                         unsigned short rightVol);
  349. /*-----------------------------------------------------------------------*/
  350.  
  351. /*
  352.     Purpose:        Gets the rate multiplier of the currently playing sound.
  353.     Side Effects:    None.
  354. */
  355. /*-----------------------------------------------------------------------*/
  356. OSErr            ASoundGetRateMul        (SoundInfoPtr theSoundInfo,
  357.                                         UnsignedFixed *theRateMul);
  358. /*-----------------------------------------------------------------------*/
  359.  
  360. /*
  361.     Purpose:        Gets the rate multiplier of the currently playing sound.
  362.     Side Effects:    None.
  363. */
  364. /*-----------------------------------------------------------------------*/
  365. OSErr            ASoundSetRateMul        (SoundInfoPtr theSoundInfo,
  366.                                         UnsignedFixed theRateMul);
  367. /*-----------------------------------------------------------------------*/
  368.  
  369. #endif